import java.util.LinkedList;
import java.util.List;

public class MovingAverage {

    int sum;
    int size;
    int index;
    List<Integer> list;
    public MovingAverage(int size) {
        this.size = size;
        sum = 0;
        index = -1;
        list = new LinkedList<>();
    }

    public double next(int val) {
        sum += val;
        ++index;
        if (index < size) {
            list.add(val);
            return (double) sum / (index + 1);
        } else {
            sum -= list.get(0);
            list.remove(0);
            list.add(val);
            return (double) sum / size;
        }
    }
}
